<!-- 收货对账查询：蹇泽阳 -->
<template>
  <div class="app-container">
    <Find :OriginalFilter="{ static: true }" :formList="formList" @findClicked="findClicked" @clickNumber="clickNumber" />
    <Find :searchImg="false" :OriginalFilter="{ static: true }" :formList="formList2" @findClicked="findClicked2" />

    <div class="mt10" style="width: 100%; background-color: white">
      <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }">
        <h1 class="f16">入库明细查询</h1>
        <Table
          :tableHeader="tableHeader"
          :tableData="tableData"
          class="mt10"
          :isLoading="isLoading"
          @currentRow="currentRow"
          :summaryData="summaryData"
          summary
          @selectList="selectTableList"
        />
      </el-card>
      <el-card shadow="never" :body-style="{ padding: '5px' }">
        <PageModule :PageData="{ total, buttonS: true }" @pageSizeChange="handleSizeChange" @pageChange="handleCurrentChange" />
      </el-card>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import { selectList } from '@/plugins/mixin'
import fileRequest from '@/utils/fileRequest'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'HarvestReconciliationInquiries'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import type { formListType } from '@/components/Find/index.vue'
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import service from '@/utils/request'
import { debounce } from 'lodash'
import { onMounted, watch } from 'vue'
const formList = ref<any>([
  {
    type: 'input',
    inputPlaceholder: '入库单号',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '送货单号',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '对账月份',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '对账方式',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '指令',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '厂商',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'date',
    dateLabel: '入库日期',
    dateValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '材料类型',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '类型',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '物料名称',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '对账单号',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '财务备注',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '仓库备注',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '品牌',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '底模',
    inputValue: ''
  },
  {
    type: 'radio',
    checkboxLabel: '未输入',
    label: '1'
  },
  {
    type: 'radio',
    checkboxLabel: '已输入',
    label: '2'
  },
  {
    type: 'radio',
    checkboxLabel: '已输入未对账',
    label: '3'
  },
  {
    type: 'radio',
    checkboxLabel: '已输入已对账',
    label: '4'
  },
  {
    type: 'radio',
    checkboxLabel: '全部',
    label: '5'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '导出明细'
  },
  {
    type: 'button',
    checkboxLabel: '查询'
  }
])

const formList2 = ref<any>([
  {
    type: 'input',
    inputPlaceholder: '面材检核单据(单)',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '大底检核单据(单)',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '包材检核单据',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '面衬检核单据',
    inputValue: ''
  }
])

// 表一模块
// 表一按钮
const findClicked = async (content: string) => {
  if (content === '查询') {
    getTableList()
  }
  if (content === '置空') {
    formList.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
  if (content === '导出明细') {
    const res = (await fileRequest.post(`/ReceiptReconciliation/exportInboundDetails`, {
      accountName: formList.value.find(
        (item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '对账方式'
      )?.selectValue,
      balanceNo: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '对账单号'
      )?.inputValue,
      brand: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '品牌')
        ?.selectValue,
      financeRecMemo: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '财务备注'
      )?.inputValue,
      financeRecYymm: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '对账月份'
      )?.inputValue,
      flag: flag.value,
      moldNo: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '底模'
      )?.inputValue,
      mtlName: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '物料名称'
      )?.inputValue,
      orderId: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '指令'
      )?.inputValue,
      purNo: '', //订单号
      purType: '', //订单类型
      recDateEnd: formList.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '入库日期'
      )?.dateValue?.[1],
      recDateStart: formList.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '入库日期'
      )?.dateValue?.[0],
      recNo: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '入库单号'
      )?.inputValue,
      remark: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '仓库备注'
      )?.inputValue,
      sendDateEnd: '', //送货日期
      sendDateStart: '', //送货日期
      sendNo: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '送货单号'
      )?.inputValue,
      seqName: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '材料类型')
        ?.selectValue,
      slipType: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '类型')
        ?.selectValue,
      vendorName: formList.value
        .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商')
        ?.selectValue?.split(' ')[0],
      vendorNo: formList.value
        .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商')
        ?.selectValue?.split(' ')[1],
      pageNum: currentPage.value,
      pageSize: pageSize.value
    })) as any
    const link = document.createElement('a') // 利用a标签自定义下载文件名
    let blob = new Blob([res.data]) // 创建Blob对象，设置文件类型
    link.style.display = 'none'
    //设置连接
    link.href = window.URL.createObjectURL(blob)
    const FileName = decodeURI(res.headers['content-disposition'].split(`utf-8''`)[1])
    link.download = FileName //自定义文件名字
    document.body.appendChild(link)
    //模拟点击事件
    link.click()
    document.body.removeChild(link)
  }
}
const findClicked2 = (content: string) => {
  if (content === '置空') {
    formList2.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
}
const tableData = ref([])
const isLoading = ref(true)
// 总计
interface summaryDataType {
  index: number
  num: number | undefined
}
const summaryData = ref<summaryDataType[]>([
  {
    index: 18,
    num: 0
  },
  {
    index: 20,
    num: 0
  }
])
// 分页器
const currentPage = ref(1)
const pageSize = ref(40)
const total = ref(0)
const handleSizeChange = (val: number) => {
  pageSize.value = val
  getTableList()
}
const handleCurrentChange = (val: number) => {
  currentPage.value = val
  getTableList()
}
const flag = ref(1)
const clickNumber = (val: any) => {
  console.log(val)

  flag.value = val
  getTableList()
}
// 获取表数据
const getTableList = debounce(async () => {
  isLoading.value = true
  let tableDataList = await service.post<any, any>('/ReceiptReconciliation/mtlPreOtherInQuery', {
    accountName: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '对账方式')
      ?.selectValue,
    balanceNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '对账单号'
    )?.inputValue,
    brand: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '品牌')
      ?.selectValue,
    financeRecMemo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '财务备注'
    )?.inputValue,
    financeRecYymm: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '对账月份'
    )?.inputValue,
    flag: flag.value,
    moldNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '底模'
    )?.inputValue,
    mtlName: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '物料名称'
    )?.inputValue,
    orderId: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '指令'
    )?.inputValue,
    purNo: '', //订单号
    purType: '', //订单类型
    recDateEnd: formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '入库日期'
    )?.dateValue?.[1],
    recDateStart: formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '入库日期'
    )?.dateValue?.[0],
    recNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '入库单号'
    )?.inputValue,
    remark: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '仓库备注'
    )?.inputValue,
    sendDateEnd: '', //送货日期
    sendDateStart: '', //送货日期
    sendNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '送货单号'
    )?.inputValue,
    seqName: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '材料类型')
      ?.selectValue,
    slipType: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '类型')
      ?.selectValue,
    vendorName: formList.value
      .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商')
      ?.selectValue?.split(' ')[0],
    vendorNo: formList.value
      .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商')
      ?.selectValue?.split(' ')[1],
    pageNum: currentPage.value,
    pageSize: pageSize.value
  })
  isLoading.value = false
  tableData.value = tableDataList.data
  total.value = tableDataList.total
  currentRow()
  summaryData.value[0].num = tableDataList.qtySum
  summaryData.value[1].num = tableDataList.amtSum
}, 500)
onMounted(() => {
  getTableList()
})
watch(
  () =>
    formList.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    getTableList()
  }
)
const tableHeader = ref([
  {
    label: '类型',
    prop: 'seqName'
  },
  {
    width: '120',
    label: '入库单号',
    prop: 'recNo'
  },
  {
    label: '对账月份',
    prop: 'financeYymm'
  },
  {
    label: '对账方式',
    prop: 'accountName'
  },
  {
    width: '120',
    label: '对账单号',
    prop: 'balanceNo'
  },
  {
    label: '入库日期',
    prop: 'recDate'
  },
  {
    label: '送货单号',
    prop: 'sendNo'
  },
  {
    label: '订购单号',
    prop: 'purNo'
  },
  {
    label: '厂商名称',
    prop: 'vendorName'
  },
  {
    label: '品牌',
    prop: 'custom'
  },
  {
    label: '指令',
    prop: 'lotNo'
  },
  {
    width: '120',
    label: '型体',
    prop: 'style'
  },
  {
    label: '材料颜色',
    prop: 'mtlColor'
  },
  {
    width: 200,
    label: '材料名称',
    prop: 'mtlName'
  },
  {
    label: '规格',
    prop: 'mtlSpec'
  },
  {
    label: '单位',
    prop: 'mtlUnit'
  },
  {
    label: '用量',
    prop: 'ttlUsage'
  },
  {
    label: '类型',
    prop: 'slipType'
  },
  {
    label: '暂收数量',
    prop: 'sendQty'
  },
  {
    label: '单价',
    prop: 'price'
  },
  {
    label: '金额',
    prop: 'amt'
  },
  {
    label: '财务备注',
    prop: 'financeRecMemo'
  },
  {
    label: '仓库备注',
    prop: 'remark'
  },
  {
    label: '备注信息',
    prop: 'remarkCw'
  },
  {
    label: '底模号',
    prop: 'moldNo'
  }
])
// 点击表给另一张表传数据
const currentTableRow = ref({}) as any
const currentRow = async (row: any = tableData.value[0] ? tableData.value[0] : {}) => {
  currentTableRow.value = row
}
const selectedLists = ref([])
const selectTableList = (selectedList: any) => {
  selectedLists.value = selectedList
}

const getSelectList = async () => {
  await selectList(formList, () => service.get('/back/order/allOrderCondition'))
  let vendorName = await service.get<any, any>('/back/vendorQuery')
  // 插入厂商代码 厂商名称
  vendorName.forEach((item: any, index: any) => {
    if (item === null) return
    formList.value
      .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商')
      ?.selectOptions?.push({
        optionKey: `${item.vendorName} ${item.vendorNo}`,
        optionLabel: `${item.vendorName} ${item.vendorNo}`,
        optionValue: `${item.vendorName} ${item.vendorNo}`,
        LeftLabel: `${item.vendorName}`,
        RightLabel: `${item.vendorNo}`
      })
    formList2.value
      .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '结算厂商')
      ?.selectOptions?.push({
        optionKey: `${item.vendorName} ${item.vendorNo}`,
        optionLabel: `${item.vendorName} ${item.vendorNo}`,
        optionValue: `${item.vendorName} ${item.vendorNo}`,
        LeftLabel: `${item.vendorName}`,
        RightLabel: `${item.vendorNo}`
      })
  })
  formList.value
    .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '对账方式')
    ?.selectOptions?.push(
      {
        optionKey: `荣阳大货`,
        optionLabel: `荣阳大货`,
        optionValue: `荣阳大货`
      },
      {
        optionKey: `荣信`,
        optionLabel: `荣信`,
        optionValue: `荣信`
      }
    )
  formList2.value
    .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '对账方式')
    ?.selectOptions?.push(
      {
        optionKey: `荣阳大货`,
        optionLabel: `荣阳大货`,
        optionValue: `荣阳大货`
      },
      {
        optionKey: `荣信`,
        optionLabel: `荣信`,
        optionValue: `荣信`
      }
    )
  formList.value
    .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '材料类型')
    ?.selectOptions?.push(
      {
        optionKey: `面材`,
        optionLabel: `面材`,
        optionValue: `面材`
      },
      {
        optionKey: `大底`,
        optionLabel: `大底`,
        optionValue: `大底`
      },
      {
        optionKey: `包材`,
        optionLabel: `包材`,
        optionValue: `包材`
      },
      {
        optionKey: `面衬`,
        optionLabel: `面衬`,
        optionValue: `面衬`
      },
      {
        optionKey: `易耗品`,
        optionLabel: `易耗品`,
        optionValue: `易耗品`
      }
    )
  formList.value
    .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '类型')
    ?.selectOptions?.push(
      {
        optionKey: `正单`,
        optionLabel: `正单`,
        optionValue: `正单`
      },
      {
        optionKey: `预加`,
        optionLabel: `预加`,
        optionValue: `预加`
      },
      {
        optionKey: `多购`,
        optionLabel: `多购`,
        optionValue: `多购`
      },
      {
        optionKey: `补料`,
        optionLabel: `补料`,
        optionValue: `补料`
      }
    )
  const remarks = (await service.get('/mtlCosts/mtlPreOtherInBack')) as any
  remarks.forEach((item: any) => {
    formList2.value
      .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '备注信息')
      ?.selectOptions?.push({
        optionKey: item,
        optionLabel: item,
        optionValue: item
      })
  })
}
onMounted(() => {
  getSelectList()
})
</script>

<style lang="less" scoped></style>
